<template>
	<view>
		<view class="content">
			<view class="input-group">
				<view class="input-row border">
					<view class="content-tab">
						<text class="title">旧</text>
						<text class="title">密</text>
						<text class="title">码</text>
					</view>
					<input type="text" password="true" v-model="old_pwd" placeholder="请输入旧密码">
				</view>
				<view class="input-row border">
					<view class="content-tab">
						<text class="title">新</text>
						<text class="title">密</text>
						<text class="title">码</text>
					</view>
					<input type="text" password="true" v-model="new_pwd" placeholder="请输入新密码">
				</view>
				<view class="input-row">
					<text class="title">确认密码</text>
					<input type="text" password="true" v-model="repwd" placeholder="请输入确认新密码">
				</view>
			</view>
			<view v-if="new_pwd!=repwd&&pwd!=''">
				<text style="color: red;">两次输入的密码不一致</text>
			</view>
			<view v-if="new_pwd===old_pwd&&new_pwd!=''">
				<text style="color: red;">新密码不能与旧密码一致</text>
			</view>
			<view class="btn-row">
				<button type="primary" :disabled="new_pwd!=repwd" class="primary" @tap="changePassword">修改密码</button>
			</view>		     
		</view>
	</view>
</template>

<script>
	import {mapState, mapMutations} from 'vuex';
	export default {
		data() {
			return {
				// account: '',
				old_pwd: '',
				new_pwd:'',
				repwd: ''
			}
		},
		computed: mapState(['hasLogin', 'userName','userType']),
		methods: {
			...mapMutations(['show']),
			changePassword(){
				let url='';
				this.show();
				console.log('change');
				if(this.userType==0){
					console.log('顾客');
					url='/users/change_my_password/'
				}else if(this.userType==1){
					console.log('商家');
					url='/users/change_shop_password/'
				}
				const res=this.$myRequest({
					url:url,
					data:{
						"telenumber":this.userName,
						"old_password":this.old_pwd,
						"new_password":this.new_pwd
					}
				}).then(respnse=>{
					if(respnse.data=='旧密码输入不正确'){
						uni.showToast({
							title:'密码错误',
							icon:'none'
						});
					}else if(respnse.data=='修改密码成功'){
						uni.showToast({
							title:'修改密码成功',
							icon:'success'
						});
					}
				})
			}
		}
	}
</script>

<style>
	@import url("../../../../common/denglu.css");
	.content-tab{
		display: flex;
		width: 4em;
		justify-content:space-between;
	}
	.input-row input{
		margin-left: 15upx;
		
	}
</style>
